package com.sgb.kjwl.view.widget;

import android.content.Context;

import com.google.gson.reflect.TypeToken;

import com.sgb.kjwl.api.GsonManager;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.swgk.core.dialog.BaseMultiAreaPopWindow;
import com.swgk.core.recyclerview.entity.BaseAreaEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 两级多选筛选地区弹框
 */

public class TwoLevelMultiAreaWindow extends BaseMultiAreaPopWindow {

    private List<BaseAreaEntity<List<BaseAreaEntity<List<BaseAreaEntity>>>>> baseAreaEntityList;
    // 一级联动数据
    private final List<BaseAreaEntity<List<BaseAreaEntity<List<BaseAreaEntity>>>>> mProvinceList = new ArrayList<>();
    // 二级联动数据
    private final List<List<BaseAreaEntity<List<BaseAreaEntity>>>> mCityList = new ArrayList<>();
    // 三级联动数据
    private final List<List<List<BaseAreaEntity>>> mDistrictList = new ArrayList<>();

    public TwoLevelMultiAreaWindow(Context context) {
        super(context);
    }


    @Override
    protected void areaClick(BaseAreaEntity baseAreaEntity, int position) {
    }

    /**
     * 获取选择的文字
     *
     * @param name
     * @param simpleName
     */
    @Override
    protected void resultContent(String name, String simpleName) {

    }

    @Override
    protected void cityMoreClick(List list, int position) {
    }

    @Override
    protected void provinceMoreClick(List list, int position) {
    }


    @Override
    protected void provinceClick(BaseAreaEntity baseAreaEntity, int position) {
    }

    @Override
    protected void cityClick(BaseAreaEntity baseAreaEntity, int position) {
    }

    @Override
    protected void areaMoreClick(List list, int position) {
    }

    /**
     * 设置数据，默认省市单选
     */
    public void setMultiData(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> listDatas, boolean isAddFirstData) {
        String cityListsStr = GsonManager.getInstance().getGson().toJson(listDatas);
        List<BaseAreaEntity<List<BaseAreaEntity<List<BaseAreaEntity>>>>> list = GsonManager.getInstance().getGson().fromJson(cityListsStr, new TypeToken<List<BaseAreaEntity<List<BaseAreaEntity<List<BaseAreaEntity>>>>>>() {
        }.getType());
        this.baseAreaEntityList = list;
        if (isAddFirstData) {
            BaseAreaEntity provinceEntity = new BaseAreaEntity();
            provinceEntity.setName("全国");
            provinceEntity.setNo("");
            provinceEntity.setSimpleName("全国");
            provinceEntity.setChildren(new ArrayList<>());

            BaseAreaEntity provinceEntity1 = new BaseAreaEntity();
            provinceEntity1.setName("全国");
            provinceEntity1.setNo("");
            provinceEntity1.setSimpleName("全国");
            provinceEntity1.setSelected(false);
            provinceEntity1.setChildren(new ArrayList<>());

            list.add(0, provinceEntity);
            for (int i = 0; i < list.size(); i++) {
                if (i != 0) {
                    BaseAreaEntity cityEntity = new BaseAreaEntity();
                    cityEntity.setName("全省");
                    cityEntity.setNo("");
                    cityEntity.setSimpleName("全省");
                    cityEntity.setSelected(false);
                    list.get(i).getChildren().add(0, cityEntity);

                    for (int j = 1; j < list.get(i).getChildren().size(); j++) {
                        BaseAreaEntity areaEntity = new BaseAreaEntity();
                        areaEntity.setName("全市");
                        areaEntity.setNo("");
                        areaEntity.setSimpleName("全市");
                        areaEntity.setSelected(false);
                        list.get(i).getChildren().get(j).getChildren().add(0, areaEntity);
                    }
                } else {
                    list.get(i).getChildren().add(0, provinceEntity1);
                }
            }
        }
        super.BaseData(list, true);
    }


    /**
     * 设置省单选
     */
    public void setProvinceSingle() {
        super.setProvinceType(false);
    }

    /**
     * 设置省多选
     */
    public void setProvinceMore() {
        super.setProvinceType(true);
    }

    /**
     * 设置市单选
     */
    public void setCitySingle() {
        super.setCityType(false);
    }

    /**
     * 设置市多选
     */
    public void setCityMore() {
        super.setCityType(true);
    }

    /**
     * 设置区单选
     */
    public void setAreaSingle() {
        super.setAreaType(false);
    }

    /**
     * 设置区多选
     */
    public void setAreaMore() {
        super.setAreaType(true);
    }

    public void setFirstListIsGone(boolean isGone) {
        super.setFirstListIsGone(isGone);
    }

    public void setSecondaryListIsGone(boolean isGone) {
        super.setSecondaryListIsGone(isGone);
    }

    public void setThreeListIsGone(boolean isGone) {
        super.setThreeListIsGone(isGone);
    }

    public void setLayoutPadding(int left, int right) {
        super.setLayoutPadding(left, right);
    }


}
